package com.wzh.mall.search.controller;

import com.wzh.mall.search.service.MallSearchService;
import com.wzh.mall.search.vo.SearchParam;
import com.wzh.mall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: mall
 * @description:
 * @author: Mr.Wang
 * @create: 2021-09-10 21:27
 **/
@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    /**
      * @Description: 自动将springmvc的封装功能
      * @Param: [param]
      * @return: java.lang.String
      * @Author: Mr.Wang
      * @Date: 2021/9/11
      * @Time: 10:30
      */      
      
    @GetMapping("/list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request){
        String queryString = request.getQueryString();
        param.set_queryString(queryString);
        // 根据页面参数 去es中去检索
        SearchResult result=mallSearchService.search(param);
        model.addAttribute("result",result);
        return "list";
    }

    @GetMapping("/list.html/{catalog3Id}")
    public String listCatalogPage(@PathVariable("catalog3Id") Long catalog3Id){

        SearchParam param=new SearchParam();
        Object result=mallSearchService.search(param);

        return "list";
    }



}
